/**
 * Description:
 * Class Name:ErasureTest
 * Date:2022/3/25 20:06
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第9章_泛型._9_5_擦除和转换;

class Apple<T extends Number>{
    T size;
    public Apple(){}
    public Apple(T size){
        this.size = size;
    }

    public void setSize(T size) {
        this.size = size;
    }

    public T getSize() {
        return size;
    }
}

public class ErasureTest {
    public static void main(String[] args) {
        Apple<Integer> a = new Apple<>(6);          // ①
        // a的getSize()方法返回Integer对象
        Integer as = a.getSize();

        // 把a对象赋给Apple变量，丢失尖括号里的类型信息
        Apple b = a;                                    // ②
        // b只知道size的类型是Number
        Number size1 = b.getSize();
        // 下面的代码将引起编译错误
//        Integer size2 = b.getSize();                    // ③
    }
}
